package com.scu.servlet;

import com.scu.dao.ykUserDao;
import com.scu.entity.ykUser;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "AddUserServlet", value = "/AddUserServlet")
public class AddUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String user_id = request.getParameter("user_id");
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        String phone = request.getParameter("phone");
        String email = request.getParameter("email");
        String register_date = request.getParameter("register_date");
        String level = request.getParameter("level");
        String is_illegal = request.getParameter("is_illegal");



        ykUser user = new ykUser();
        user.setName(name);
        user.setUser_id(Integer.parseInt(user_id));//todo
        user.setPassword(password);
        user.setPhone(phone);
        user.setEmail(email);
        user.setRegister_date(register_date);
        user.setLevel(level);
        user.setIs_illegal(Integer.parseInt(is_illegal));




        System.out.println(user);
        try {
            new ykUserDao().insert(user);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }





    }
}
